﻿using System;
using CarTrackr.Business.Validation;
using CarTrackr.Data.Attributes;


namespace CarTrackr.Business
{
    public class Refuelling :BusinessBase 
    {

        [DbField(Name = "Id")]
        public Guid Id { get; set;}

        [DbField(Name = "Date")]
        public DateTime Date { get; set;}

        [DbField(Name = "ServiceStation")]
        public string   ServiceStation { get; set;}

        [DbField(Name = "Kilometers")]
        public decimal    Kilometers { get; set;}

        [DbField(Name = "Liters")]
        public decimal  Liters { get; set;}

        [DbField(Name = "PricePerLiter")]
        public decimal  PricePerLiter { get; set;}

    
        public decimal Total
        {
           get
           {
               return Liters*PricePerLiter;
           }
        }

        public decimal Usage
        {
           get
           {
               if  (Liters == 0) return 0; 
               return Liters/Kilometers;
           }
        }

        public Refuelling()
        {
            CreateRules();
        }


        public void  CreateRules()
        {

             AddRule(new RequiredRule    {PropertyName = "Date"});
             AddRule(new AboveZeroRule   {PropertyName = "Kilometers"});
             AddRule(new AboveZeroRule   {PropertyName = "Liters"});
             AddRule(new AboveZeroRule   {PropertyName = "PricePerLiter"});
        }

 
    }



}


 

 